package com.kmist.xiakexing.data;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.kmist.xiakexing.tools.Config;
import com.kmist.xiakexing.utils.LiaotianBean;

public class LiaotianDao implements ILiaotianDao{

    private static LiaotianDao sInstance = null;
    private ILiaotianDaoCallback mCallback;

    private XiakexingDBHelper xiakexingDBHelper;
    private SQLiteDatabase db;
    private Cursor c;

    public LiaotianDao() {
        xiakexingDBHelper = new XiakexingDBHelper(Config.context);
    }


    public static LiaotianDao getsInstance() {
        if(sInstance == null){
            synchronized (LiaotianDao.class){
                sInstance = new LiaotianDao();
            }
        }
        return sInstance;
    }

    @Override
    public void setCallback(ILiaotianDaoCallback callback) {
        this.mCallback = callback;
    }

    @Override
    public void addMsg(LiaotianBean liaotianBean) {
        try {
            db = xiakexingDBHelper.getReadableDatabase();
            String sql = "insert into ggliaotian(name,msg,uid) values(?,?,?)";
            db.execSQL(sql,new Object[]{liaotianBean.getName(), liaotianBean.getMsg(), liaotianBean.getUid()});
            if(mCallback!= null){
                mCallback.onMsgAdded();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            db.close();
        }
    }

    @Override
    public void getMsg() {

    }
}
